<?php
  require(dirname(__FILE__).'/global.php');
  require(ROOT.'/admin/isLogin.php');     
  require(ROOT.'/include/file.class.php');
  
  $action = $_GET['action'];
  if($action == 'down')
  {
      $filename = $_GET['file'];
      $file = dirname(__FILE__).'/../bak/'.$filename;
      if(file_exists($file))
      {
          $fp = @fopen($file,"r");
          header("Content-type:application/octet-stream");
          header("Accept-Ranges:bytes");
          header("Accept-Length:".filesize($file));
          header("Content-Disposition:attachment; filename=".$_GET['file']);
          echo @fread($fp,filesize($file));
          @fclose($fp);
      }
      else
      {
          $smarty->assign('tip','文件不存在');
      }
  }
  else if($action == 'delete' )
  {
      $filename = $_GET['file'];
      $file = ROOT.'/bak/'.$filename;
      if(file_exists($file))
      {
          @unlink($file);                                          
          $smarty->assign('tip','删除成功');
      }
      else
      {
          $smarty->assign('tip','文件不存在');
      }
  }
  else if($action == 'restore')
  {
      $filename = $_GET['file'];                    
      $file = ROOT.'/bak/'.$filename;
      if(file_exists($file))
      { 
          $db->restore($file);
          $smarty->assign('tip','还原成功');
      }
      else
      {
          $smarty->assign('tip','文件不存在');
      }
  }
  $array = FileUtil::getFileList(ROOT.'/bak', 'sql');
  $smarty->assign('array',$array);
  $smarty->display('db_import.html');
  $db->close();
?>